--#include "data\config\hero\HeroRuneConfig.lua" once	-消耗配置
--#include "data\functions\Activity\OpenServer\OpenServerPKRank.lua" once  
--#include "data\functions\Activity\OpenServer\OpenServerSports.lua" once

--英雄符文升级处理
function HeroRuneHandle( sysarg)
	local var = Actor.getStaticVar(sysarg)

	local Runelevel = Actor.getIntProperty(sysarg, PROP_ACTOR_RUNE_LEVEL)
	
	HeroRuneHandleImpl(sysarg, Runelevel + 1)
		
end

function HeroRuneHandleImpl(sysarg, nRuneLevel)
	local config = HeroRuneConfig.HeroRuneConsumes[nRuneLevel]
	if not config then
		System.trace("Can not find HeroRuneConsumes config, nRuneLevel="..nRuneLevel)
		Actor.sendTipmsg(sysarg,Lang.ScriptTips.HeroRune001,ttFlyTip)
		return
	end
	
	--条件检测
	local bCheck = CheckHeroRuneCondition(sysarg, config)
	if bCheck ~= true then
		return
	end
	
	--local currentLevel = Actor.getIntProperty(sysarg, PROP_CREATURE_LEVEL)
	if not Actor.checkActorLevel(sysarg, HeroRuneConfig.activeLevel, 0) then
		Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.COM0055, HeroRuneConfig.activeLevel),ttFlyTip)
		return
	end

	if not DoConsumeCond( sysarg, config.consumes, 1, LogIds.HeroRuneLogId, Lang.LogTips.HeroRune ) then
		return
	end
	
	Actor.SetHeroRune(sysarg, nRuneLevel)
	
	local level =  math.floor((nRuneLevel - 1)/HeroRuneConfig.stepNum)
	local step = nRuneLevel - level * HeroRuneConfig.stepNum
	local msg = string.format(Lang.ScriptTips.HeroRune002, level, step)
	Actor.sendTipmsg(sysarg, msg, ttFlyTip)

	OpenServerPKRankTriggleEvent(sysarg, enOpenServerRank_HeroRune, nRuneLevel, 0)
	OpenServerTriggleEvent(sysarg, enOpenServerId_HeroRune, nRuneLevel, 0)   --开服活动符文竞技
	OnCarnivalOpenServerRankTriggerEvent(sysarg, Carnival_Rank_Type_HeroRune_3, nRuneLevel)
end

--条件检测
function CheckHeroRuneCondition(sysarg, config)

	--local level = Actor.getIntProperty(sysarg, PROP_CREATURE_LEVEL)
	local level = 0
	local circle = 0
	
	if config.reqLevel then
		level = config.reqLevel
	end	

	if config.reqCircle then
		circle = config.reqCircle
	end	

	if not Actor.checkActorLevel(sysarg, level, circle)then
		if circle > 0 then
			Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.HeroRune004, circle), ttFlyTip)
		else
			Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.HeroRune003, level), ttFlyTip)
		end
		return false
	end

	if not CheckConsumeCond( sysarg, config.consumes, 1 ) then
		--Actor.sendTipmsg(sysarg, Lang.ScriptTips.Reincarnation002, ttFlyTip)
		return false
	end
	
	return true
end